# -*- coding: utf-8 -*-

'''eof
name:婚姻状况
code:Married
tableName:
columnName:
groups:个人通用
dependencies:IC_DSJ_2D
type:常用指标
datasourceType:在线指标
description:客户当前的婚姻状况
eof'''

import sys
import json

reload(sys)
sys.setdefaultencoding('utf-8')

# IC为个人征信数据源
# IC = {'ICRIdentity':[{ "MaritalState": "wei婚"}]}

null_type_list = ['', None, 'null', 'Null', 'NULL', '/']

def PMMFormat():
    # 婚姻状况
    try:
        data = IC_DSJ_2D.get("data").get("PMM")[0].get("PB02")
        if data is None:
            return [{}]
        else:
            return data
    except:
        return [{}]

marital_state_list = [u'已婚', u'未婚', u'离婚', u'丧偶']

code_dict = {"10":u"未婚", "20":u"已婚", "30":u"丧偶", "40":u"离婚", "91":u"单身", "99":u"未知"}

def getIG03():
    try:
        PB02 = PMMFormat()
        if PB02 in null_type_list:
            return u'缺失值'
        else:
            PB020D01 = PB02[0].get('PB020D01')
            if PB020D01 in null_type_list:
                return u'缺失值'
            else:
                if PB020D01 == '91':
                    return u'未婚'
                elif PB020D01 == '99':
                    return u'缺失值'
                else:
                    marital_state = code_dict.get(PB020D01)
                    if marital_state in marital_state_list:
                        return marital_state
                    else:
                        return u'缺失值'
    except:
        return u'缺失值'

result = getIG03()

